package comp6231.project.replica.dimitri;


import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author dimitri.tiago
 *
 */
public class StockReader
{
    private Scanner input;

    private ArrayList<Integer> itemIDList;
    private ArrayList<Integer> numberOfItemsList;

    public void openFile(String filename)
    {
		try
		{
		    input 		      = new Scanner(new File(filename));
		    itemIDList 		  = new ArrayList<Integer>();
		    numberOfItemsList = new ArrayList<Integer>();
		} 
		catch (FileNotFoundException e)
		{
		    e.printStackTrace();
		}
    }

    public void readRecords()
    {
		while (input.hasNextLine())
		{
		    // read next record
		    String nextRecord 	  = input.nextLine();
	
		    // parse record
		    String[] recordTokens = nextRecord.split(" ");
		    int nextItemID 	  	  = Integer.parseInt(recordTokens[0].trim());
		    int numberOfItems     = Integer.parseInt(recordTokens[1].trim());
	
		    itemIDList.add( Integer.valueOf(nextItemID) );
		    numberOfItemsList.add( Integer.valueOf(numberOfItems) );
		}
		
		input.close();
    }

    public int[] getItemIDs()
    {
		int[] itemIds = new int[itemIDList.size()];
		for (int i = 0; i < itemIds.length; i++)
		{
		    itemIds[i] = (itemIDList.get(i)).intValue();
		}
	
		return itemIds;
    }

    public int[] getNumberOfItems()
    {
		int[] numOfItems = new int[numberOfItemsList.size()];
		for (int i = 0; i < numOfItems.length; i++)
		{
		    numOfItems[i] = (numberOfItemsList.get(i)).intValue();
		}
	
		return numOfItems;
    }
}
